package cn.com.cloudpioneer.evaluate.common;

import cn.com.cloudpioneer.evaluate.utils.CustomException;
import cn.com.cloudpioneer.evaluate.utils.OPResponse;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @auther maruikai
 * @create 2023/5/19-10:56
 */
@Aspect
@Component
public class AOP {

    private static final Logger LOGGER = LoggerFactory.getLogger(AOP.class);


    @Around(value = "execution(Object cn.com.cloudpioneer.evaluate.controller..*.*(..))")
    public Object doAround_unify_article(ProceedingJoinPoint pjp) throws Throwable {
        try {
            return new OPResponse(pjp.proceed());
        } catch (CustomException e) {
            LOGGER.warn("自定义异常：" + e.getMessage() + " - " + pjp.getSignature().toString());
            return new OPResponse(e.getCode(), e.getMessage(), false);
        } catch (Throwable e) {
            LOGGER.error("捕获接口异常", e);
            return new OPResponse(500, "接口异常，请稍后再试", false);
        }
    }
}
